// **************************
// I2C Wii Motion Plus 
// **************************
// I2C adress 1: 0xA6 (8bit)    0x53 (7bit)
// I2C adress 2: 0xA4 (8bit)    0x52 (7bit)


void i2c_WMP_init(uint8_t d) {
	delay(d);
	i2c_rep_start(0xA6 + 0);//I2C write direction => 0
	i2c_write(0xF0); 
	i2c_write(0x55); 
	delay(d);
	i2c_rep_start(0xA6 + 0);//I2C write direction => 0
	i2c_write(0xFE); 
	i2c_write(0x05); 
	delay(d);

	if (d>0) {
		uint8_t numberAccRead = 0;
		for(uint8_t i=0;i<100;i++) {
			delay(3);
			if (rawIMU(0) == 0) numberAccRead++; // we detect here is nunchuk extension is available
		}
		if (numberAccRead>25)
			nunchukPresent = 1;
		delay(10);
	}
}

void i2c_WMP_getRawADC() {
	TWBR = ((16000000L / I2C_SPEED) - 16) / 2; // change the I2C clock rate
	i2c_rep_start(0xA4 + 0);//I2C write direction => 0
	i2c_write(0x00);
	i2c_rep_start(0xA4 + 1);//I2C read direction => 1
	for(uint8_t i = 0; i < 5; i++)
		rawADC_WMP[i]=i2c_readAck();
	rawADC_WMP[5]= i2c_readNak();
}